﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once

#include "GbmpDefines.h"
#include "GmUiInplaceEditCommon.h"
#include "GmCommunicationProtocolHeader.h"
#include <string>


namespace gcmp
{
    class ICommunicationProtocol;
    class NdbObject;
    class RpcServerInfo;

    class GM_UI_INPLACE_EDIT_COMMON_EXPORT CommunicationProtocolUtils
    {
    public:
        //将通信信息进行编码，并输出
        static bool EncodeProtocol(const ICommunicationProtocol* pProtocol, std::vector<char>& buffer);

        //将通信信息进行解码，并输出
        static bool DecodeProtocol(ICommunicationProtocol* pProtocol, const std::vector<char>& buffer);

        // 发送rpc消息
        static bool SendIpcMessage(u_short port, FunctionType functionType, OperationType operationType, const gcmp::NdbObject* pContent);
        static bool SendIpcSharedMemoryMessage(u_short port, OperationType operationType, const gcmp::NdbObject* pContent);

        // 心跳测试
        static OwnerPtr<RpcServerInfo> SendHeartBeat(u_short port);

    private:
        friend class SystemProcessEventHandler;
        static void SetHeartBeatInfo(OwnerPtr<RpcServerInfo> opInfo);
    };
}
